clear
g = 20;

q = 2;

no_packets_sent = 300;

P = zeros(g+1); %Vi vil gerne have rank 0 med som start

r= 0:g; %Rank vector for

state=1;

%gamma = sym('gamma');

gamma=[0.5 0.3];

%loop_pr = 1-gamma*(1-1/q^(g-r));

%rank_pr = gamma*(1-1/q^(g-r));

% %%%%% For a single Layer %%%%%
% for n = 1:length(P)
%         
%     if n==length(P)
%         P(state,state)=1;
%     else
%         P(state,state) = 1-gamma*(1-1/q^(g-r(n)));
%         P(state,state+1) = gamma*(1-1/q^(g-r(n)));
%         %P(state,state) = loop_pr(n);
%         %P(state,state+1) = rank_pr(n);
%     end
%     
%     state=state+1;
% end
% 
% for packets = 1:no_packets_sent
%     v(1,1)=1;
%     
%     result = v(1,:)*(P^packets);
%     
%     resultat(packets) = result(1,g+1);
% end



rang = 1;

gamma=[0.7 0.3];
K1 = 32;
K2 = 64;
P = zeros([K2+1 K2+1]);
r=0:K2;
resultat=zeros(no_packets_sent);
%%%% For multiple Layers %%%%

for n = 1:length(P)
    
    if n==length(P)
        P(state,state)=1;
    else
        if n>K1+1
            P(state,state) = (gamma(2)/q^(K2-r(n)))+gamma(1);
            P(state,state+1) = gamma(2)*(1-1/q^(K2-r(n)));
            'L2'
        else
            P(state,state) = (gamma(2)/q^(K2-r(n)))+(gamma(1)/q^(K1-r(n)));
            'L1+L2'
            P(state,state+1) = 1-((gamma(2)/q^(K2-r(n)))+(gamma(1)/q^(K1-r(n))));
        end
        
        %P(state,state) = loop_pr(n);
        %P(state,state+1) = rank_pr(n);
    end
    
    state=state+1;
end
P

for packets = 1:no_packets_sent
    v = zeros(K2+1);
    v(1,1)=1;
    
    result = v(1,:)*(P^packets);
    result;
    resultat(packets) = result(1,K2+1);
end




plot(resultat)


